package bloomfilter;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

/**
 * 布隆过滤器
 */
public class Test {
	
	private static int expectedInsertions = 1000000; //预计要插入多少数据
	private static double fpp = 0.01; //期望的误判率
	
	private static BloomFilter<Integer> bloomFilter =
			BloomFilter.create(Funnels.integerFunnel(), expectedInsertions, fpp);

	public static void main(String[] args) {
		//插入1000000数据到bloomFilter中
        for (int i = 0; i < 1000000; i++) {
            bloomFilter.put(i);
        }
        
        int count = 0; // 误判次数
        for (int i = 1000000; i < 2000000; i++) {
        	if(bloomFilter.mightContain(i)) {
        		count++;
        		System.out.println(i + "误判了");
        	}
        }
        System.out.println("总共的误判数:" + count);
	}

}
